//
//  AccountSafetyViewController.m
//  Bees
//
//  Created by NowYouCanSee on 2019/1/4.
//  Copyright © 2019 xiaohan. All rights reserved.
//

#import "AccountSafetyViewController.h"
#import "ChangePwdViewController.h"
#import "InputBeesKeyViewController.h"
@interface AccountSafetyViewController ()

@end

@implementation AccountSafetyViewController

- (instancetype)init
{
    return [super initWithStyle:UITableViewStylePlain];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}
- (void)setupUI{
    self.title = XLocalized(@"账户安全");
    LMJWordArrowItem *item0 = [LMJWordArrowItem itemWithTitle:XLocalized(@"修改密码") subTitle:@""];
    item0.destVc = ChangePwdViewController.class;
    LMJWordArrowItem *item1 = [LMJWordArrowItem itemWithTitle:XLocalized(@"导出私钥") subTitle: @""];
    kWeakSelf(self);
    item1.itemOperation = ^(NSIndexPath *indexPath) {
        InputBeesKeyViewController *vc = [InputBeesKeyViewController new];
        vc.private_key = kCurUser.private_key;
        [weakself.navigationController pushViewController:vc animated:YES];
    };
    LMJItemSection *section = [LMJItemSection sectionWithItems:@[item0,item1] andHeaderTitle:nil footerTitle:nil];
    [self.sections addObject:section];
    self.tableView.tableFooterView = [UIView new];
    [self.tableView registerClass:UITableViewHeaderFooterView.class forHeaderFooterViewReuseIdentifier:@"foot"];
}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UITableViewHeaderFooterView *foot = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"foot"];
    foot.contentView.backgroundColor = [UIColor clearColor];
    XThemeFlatButton *footBtn = [foot.contentView viewWithTag:1001];;
    if (!footBtn) {
        footBtn = [XThemeFlatButton button];
        [footBtn setTitle:XLocalized(@"退出Bees") forState:UIControlStateNormal];
        footBtn.frame = CGRectMake(kNormalSpace, AdaptedWidth(80), kScreenWidth-2*kNormalSpace, AdaptedWidth(40));
        [foot.contentView addSubview:footBtn];
        kWeakSelf(self);
        [footBtn addTapBlock:^(UIButton * _Nonnull btn) {
            [XAlertTool alertTitle:@"确认退出Bees?" message:nil cancelAction:^{
                
            } sureAction:^{
                [kUserManager logout:^(BOOL success, NSString *des) {
                    [weakself.view makeToast:des];
                    if (success) {
                        [weakself.navigationController popToRootViewControllerAnimated:YES];
                    }
                }];
            }];
        }];
    }
    return foot;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return AdaptedWidth(120);
}
@end
